package com.fr.data.core.define;

import com.fr.base.FRContext;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.ChartData;
import com.fr.data.ChartDataModel;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.impl.ReportChartData;
import com.fr.data.util.function.DataFunction;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MoreNameCDDefinition extends TableDataDefinition
{
  private static final long serialVersionUID = 2020690082058297818L;
  public static final String XML_TAG = "MoreNameCDDefinition";
  private ChartSummaryColumn[] chartSummaryColumn;

  public MoreNameCDDefinition()
  {
  }

  public MoreNameCDDefinition(TableData paramTableData, String paramString, ChartSummaryColumn[] paramArrayOfChartSummaryColumn)
  {
    super(paramTableData, paramString);
    setChartSummaryColumn(paramArrayOfChartSummaryColumn);
  }

  public void reset()
  {
    super.reset();
    this.chartSummaryColumn = null;
  }

  protected int[] createSeriesNameArray()
    throws TableDataException
  {
    int[] arrayOfInt = new int[this.chartSummaryColumn.length];
    int i = 0;
    int j = this.chartSummaryColumn.length;
    while (i < j)
    {
      for (int k = 0; k < this.tableData.getColumnCount(); ++k)
        if (ComparatorUtils.tableDataColumnNameEquals(this.chartSummaryColumn[i].getName(), this.tableData.getColumnName(k)))
          arrayOfInt[i] = k;
      ++i;
    }
    return arrayOfInt;
  }

  public ChartData createChartData()
  {
    if (this.tableData == null)
      return ChartDataModel.defaultChartData;
    ReportChartData localReportChartData = ChartDataModel.defaultChartData;
    try
    {
      DataFunction localDataFunction;
      ArrayList localArrayList3;
      int l;
      int i1;
      ArrayList localArrayList1 = new ArrayList();
      ArrayList localArrayList2 = new ArrayList();
      int i = createCategoryNameArray(localArrayList2);
      Object[] arrayOfObject = localArrayList2.toArray();
      int[] arrayOfInt = createSeriesNameArray();
      String[] arrayOfString = new String[this.chartSummaryColumn.length];
      for (int j = 0; j < this.chartSummaryColumn.length; ++j)
        if (this.chartSummaryColumn[j].getCustomName() != null)
          arrayOfString[j] = this.chartSummaryColumn[j].getCustomName();
        else
          arrayOfString[j] = this.chartSummaryColumn[j].getName();
      if (i == -1)
      {
        if ((localArrayList2 == null) || (localArrayList2.toArray().length != 1))
          break label449;
        j = 0;
        k = arrayOfInt.length;
        while (true)
        {
          if (j >= k)
            break label449;
          localDataFunction = this.chartSummaryColumn[j].getFunction();
          localArrayList3 = new ArrayList();
          l = 0;
          i1 = this.tableData.getRowCount();
          while (l < i1)
          {
            localDataFunction.addData(this.tableData.getValueAt(l, arrayOfInt[j]));
            ++l;
          }
          localArrayList3.add(localDataFunction.getResult());
          localDataFunction.reset();
          localArrayList1.add(localArrayList3.toArray());
          ++j;
        }
      }
      j = 0;
      int k = arrayOfInt.length;
      while (j < k)
      {
        localDataFunction = this.chartSummaryColumn[j].getFunction();
        localArrayList3 = new ArrayList();
        l = 0;
        i1 = arrayOfObject.length;
        while (l < i1)
        {
          int i2 = 0;
          int i3 = this.tableData.getRowCount();
          while (i2 < i3)
          {
            if (this.tableData.getValueAt(i2, i).equals(arrayOfObject[l]))
              localDataFunction.addData(this.tableData.getValueAt(i2, arrayOfInt[j]));
            ++i2;
          }
          localArrayList3.add(localDataFunction.getResult());
          localDataFunction.reset();
          ++l;
        }
        localArrayList1.add(localArrayList3.toArray());
        ++j;
      }
      label449: Object[][] arrayOfObject1 = (Object[][])localArrayList1.toArray(new Object[localArrayList1.size()][]);
      localReportChartData = new ReportChartData(arrayOfObject, arrayOfString, arrayOfObject1);
    }
    catch (TableDataException localTableDataException)
    {
      FRContext.getLogger().log(Level.WARNING, localTableDataException.getMessage(), localTableDataException);
    }
    try
    {
      this.tableData.release();
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
    return localReportChartData;
  }

  public void setChartSummaryColumn(ChartSummaryColumn[] paramArrayOfChartSummaryColumn)
  {
    this.chartSummaryColumn = paramArrayOfChartSummaryColumn;
  }

  public ChartSummaryColumn[] getChartSummaryColumn()
  {
    return this.chartSummaryColumn;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    int i;
    paramXMLPrintWriter.startTAG("MoreNameCDDefinition");
    super.writeXML(paramXMLPrintWriter);
    if (this.chartSummaryColumn != null)
      for (i = 0; i < this.chartSummaryColumn.length; ++i)
        this.chartSummaryColumn[i].writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("ChartSummaryColumn"))
      {
        ChartSummaryColumn localChartSummaryColumn = (ChartSummaryColumn)paramXMLableReader.readXMLObject(new ChartSummaryColumn());
        if (this.chartSummaryColumn == null)
        {
          this.chartSummaryColumn = new ChartSummaryColumn[] { localChartSummaryColumn };
        }
        else
        {
          ChartSummaryColumn[] arrayOfChartSummaryColumn = this.chartSummaryColumn;
          this.chartSummaryColumn = new ChartSummaryColumn[arrayOfChartSummaryColumn.length + 1];
          System.arraycopy(arrayOfChartSummaryColumn, 0, this.chartSummaryColumn, 0, arrayOfChartSummaryColumn.length);
          this.chartSummaryColumn[arrayOfChartSummaryColumn.length] = localChartSummaryColumn;
        }
      }
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    MoreNameCDDefinition localMoreNameCDDefinition = (MoreNameCDDefinition)super.clone();
    if (this.chartSummaryColumn != null)
    {
      ChartSummaryColumn[] arrayOfChartSummaryColumn = new ChartSummaryColumn[this.chartSummaryColumn.length];
      for (int i = 0; i < this.chartSummaryColumn.length; ++i)
        arrayOfChartSummaryColumn[i] = ((ChartSummaryColumn)this.chartSummaryColumn[i].clone());
      localMoreNameCDDefinition.setChartSummaryColumn(arrayOfChartSummaryColumn);
    }
    return localMoreNameCDDefinition;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof MoreNameCDDefinition))
      return false;
    MoreNameCDDefinition localMoreNameCDDefinition = (MoreNameCDDefinition)paramObject;
    for (int i = 0; i < this.chartSummaryColumn.length; ++i)
      if (!(localMoreNameCDDefinition.chartSummaryColumn[i].equals(this.chartSummaryColumn[i])))
        return false;
    return true;
  }
}